﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.ServiceModel;
using System.Runtime;
using System.Runtime.Serialization;
using System.ServiceModel.Description;
using ibba.agil.monitor.service;

namespace ibba.agil.monitor.host
{
    class Program
    {
        static void Main(string[] args)
        {
            var __config = System.Configuration.ConfigurationManager.AppSettings;
            var baseAddr = __config.GetValues("ServiceHost").First();

            Uri tcpAddress = new Uri(baseAddr);

            var serviceType = typeof(Monitor);
            var serviceHost = new ServiceHost(serviceType);
            var contractType = typeof(IMonitor);

            // Configuração de Bind net.tcp otimizado
            NetTcpBinding __netProxyBind = new NetTcpBinding();
            BasicHttpBinding httpBind = new BasicHttpBinding();

            var __defaultTimer = TimeSpan.FromMinutes(30.0);
            var __sizes = 248536;

            __netProxyBind.MaxBufferSize = __sizes;
            __netProxyBind.MaxReceivedMessageSize = __sizes;
            __netProxyBind.MaxConnections = 30;
            __netProxyBind.MaxBufferPoolSize = 10;

            __netProxyBind.Security.Mode = SecurityMode.Transport;
            __netProxyBind.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;


            __netProxyBind.TransferMode = TransferMode.Buffered;
            __netProxyBind.TransactionFlow = false;

            __netProxyBind.ReaderQuotas.MaxStringContentLength = __sizes;
            __netProxyBind.ReaderQuotas.MaxArrayLength = __sizes;
            __netProxyBind.ReaderQuotas.MaxBytesPerRead = __sizes;
            __netProxyBind.ReaderQuotas.MaxNameTableCharCount = __sizes;

            __netProxyBind.CloseTimeout = __defaultTimer;
            __netProxyBind.OpenTimeout = __defaultTimer;
            __netProxyBind.SendTimeout = __defaultTimer;
            
 

            serviceHost.AddServiceEndpoint(contractType, __netProxyBind, tcpAddress);

            serviceHost.Open();
            Console.WriteLine("Serviço Ativo");
            Console.ReadLine();
            serviceHost.Close();
        }
    }
}
